public class Solution278 {

    int bad;

    boolean isBadVersion(int version){
        return version>=bad?true:false;
    }

    public int firstBadVersion(int n) {
        int l=1,r=n,ans=-1;
        while (l<=r){
            int mid=l+(r-l)/2;
            if (isBadVersion(mid)){
                ans=mid;
                r=mid-1;
            }else{
                l=mid+1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution278 solution278=new Solution278();
        solution278.bad=4;
        System.out.println(solution278.firstBadVersion(5));
    }
}
